package com.dailyblue.java.standard.design.观察者模式;

import java.util.Stack;

// 福彩主题
public class LotterySubject implements Subject {
    // 福彩的彩票中奖号码
    private Integer num = (int) (Math.random() * 100 + 1);
    // 所有的观察者
    private Stack<ObServer> stack = new Stack<>();

    @Override
    public void registerObServer(ObServer obServer) {
        stack.push(obServer);
    }

    @Override
    public void removeObServer(ObServer obServer) {
        if (stack.contains(obServer)) {
            stack.remove(obServer);
        }
    }

    @Override
    public void advice() {
        String message = "亲爱的彩民朋友们，本期中奖号码是：" + num;
        for (ObServer ob : stack) {
            ob.update(message);
        }
    }
}
